package LC438;

import org.junit.Test;

import java.awt.*;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class LC438 {
    public static void main(String[] args) {
        String s1="cbaebabacd";
        String s2="abc";
        //String s1="abab";
        //String s2="ab";
        Solution s=new Solution();
        List<Integer> result=s.findDiffPositinString(s1,s2);
        System.out.println(result);
    }

    public static class Solution {

        public static List<Integer> findDiffPositinString(String s,String p)
        {
            List<Integer> result = new ArrayList<>();
            int length=s.length();
            int length2=p.length();
            int left=0;
            int right=left+length2;
            HashMap<Character,Integer> pmap=new HashMap<>();
            for(char c:p.toCharArray())
            {
                pmap.put(c,pmap.getOrDefault(c,0)+1);
            }

            while(right<=length)
            {
                String temp=s.substring(left,right);
                if(check(temp,pmap))
                {
                    result.add(left);
                }
                left++;
                right++;

            }
            return result;

        }
        public static boolean check(String s,HashMap<Character,Integer> pmap)
        {
            HashMap<Character,Integer> smap=new HashMap<>();
            for(char c:s.toCharArray())
            {
                smap.put(c,smap.getOrDefault(c,0)+1);
            }
            for(char c:pmap.keySet())
            {
                if(!smap.containsKey(c)||!smap.get(c).equals(pmap.get(c)))
                    return false;
            }
            return true;
        }

    }







//        @Test
//        public void test()
//        {
//            boolean bool = true;
//            char ch = 'A';
//            int i = 10;
//            long l = 100000L;
//            float f = 10.5f;
//            double d = 99.99;
//
//            System.out.println(String.valueOf(bool));  // 输出 "true"
//            System.out.println(String.valueOf(ch));    // 输出 "A"
//            System.out.println(String.valueOf(i));     // 输出 "100"
//            System.out.println(String.valueOf(l));     // 输出 "100000"
//            System.out.println(String.valueOf(f));     // 输出 "10.5"
//            System.out.println(String.valueOf(d));     // 输出 "99.99"
//            System.out.println(String.valueOf(ch)+String.valueOf(l)+String.valueOf(f)+String.valueOf(d));
//        }
}


